package com.wxd.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    //=================== topic主题模式  ====================
    /*XX客运段队列*/
    @Bean
    public Queue topicKyd() {
        return new Queue("topic.kyd");
    }
    /*XX机务段队列*/
    @Bean
    public Queue topicJwd() {
        return new Queue("topic.jwd");
    }

    /*接收来自XX的消息队列*/
    @Bean
    public Queue returnJwd() {
        return new Queue("return.jwd");
    }



    /**
     * 定义个topic交换器
     * @return
     */
    @Bean
    TopicExchange topicExchange() {
        // 定义一个名为fanoutExchange的fanout交换器
        return new TopicExchange("topicExchange");
    }

    /**
     * 将定义的topicA队列与topicExchange交换机绑定
     * @return
     */
    @Bean
    public Binding bindingTopicExchangeWithKyd() {
        return BindingBuilder.bind(topicKyd()).to(topicExchange()).with("kyd");
    }

    /**
     * 将定义的topicB队列与topicExchange交换机绑定
     * @return
     */
    @Bean
    public Binding bindingTopicExchangeWithJwd() {
        return BindingBuilder.bind(topicJwd()).to(topicExchange()).with("jwd");
    }
}